import http from '../../tool/http'
import api from '../../tool/api'

const state={
    tableData:[],
    page:0,
    dangqian2:1,
    thisOrder:[]
}

const getters={
    totalPage2:state=>state.page,
    requestPage2:state=>(state.dangqian2-1)*8,
}

const actions={
    pageData({commit},num){
        return http({
            url:api.allUnfinOrderPage,
            method:'post', 
            data:{num1:num,num2:8}
        }).then(res=>{
            console.log(res.data.data);
            commit('pageData1',res.data.data)
        })
    },
    totalPage({commit}){
        return http({
            url:api.allUnfinOrder,
            method:'post',
        }).then(res=>{
            console.log(res.data.count);
            commit('myPage',res.data.count)
        })
    },
    myCurrentChange({commit},num){
        commit('myCurrentChange',num)
    },
    thisDishes({commit},num){
        return http({
            url:api.getOrder,
            method:'post',
            data:{main_id:num}
        }).then(res=>{
            commit('thisDishes',res.data.data)
        })
    },
    cancelMyOrder({commit},num){
        return http({
            url:api.cancelOrder,
            method:'post',
            data:{main_id:num}
        }).then(res=>{
            console.log(res);
            
            return res.data.code
        })
    },
    dangqianInit2({commit}){
        commit('dangqianInit2')
    }
}

const mutations={
    pageData1(state,obj){
        state.tableData=obj
    },
    myPage(state,num){
        state.page=num
    },
    myCurrentChange(state,num){
        state.dangqian2=num
    },
    thisDishes(state,arr){
        state.thisOrder=arr
    },
    dangqianInit2(state){
        state.dangqian2=1
    }
}

export default{
    state,actions,mutations,getters
}